home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / emulator / bsvc-1.000 / bsvc-1 / bsvc-1.0.4 / src / Framework / RegInfo.cxx < prev    next >
C/C++ Source or Header  |  1995-07-26  |  4KB  |  151 lines

  1. /////////////////////////////////////////////////////////////////////////////// //
  2. // $Id: RegInfo.cxx,v 1.1 1994/02/18 19:49:58 bmott Exp $
  3. /////////////////////////////////////////////////////////////////////////////// //
  4. // RegInfo.cxx
  5. //
  6. //   This class is used by BasicCPU (and derived classes) to manage a list of
  7. // of register structures.
  8. //
  9. //
  10. // BSVC "A Microprocessor Simulation Framework"
  11. // Copyright (c) 1993
  12. // By: Bradford W. Mott
  13. // October 25,1993
  14. //
  15. ///////////////////////////////////////////////////////////////////////////////
  16. // $Log: RegInfo.cxx,v $
  17. // Revision 1.1  1994/02/18  19:49:58  bmott
  18. // Initial revision
  19. //
  20. ///////////////////////////////////////////////////////////////////////////////
  21.  
  22. #include <string.h>
  23. #include "RegInfo.hxx"
  24.  
  25. ///////////////////////////////////////////////////////////////////////////////
  26. // One of the RegisterInformation constructor
  27. ///////////////////////////////////////////////////////////////////////////////
  28. RegisterInformation::RegisterInformation(const char* n,const char* v,
  29.                                          const char *d)
  30. {
  31.   name=new char[strlen(n)+1];
  32.   hex_value=new char[strlen(v)+1];
  33.   description=new char[strlen(d)+1];
  34.  
  35.   strcpy(name,n);
  36.   strcpy(hex_value,v);
  37.   strcpy(description,d);
  38. }
  39.  
  40. ///////////////////////////////////////////////////////////////////////////////
  41. //  The other RegisterInformation constructor
  42. ///////////////////////////////////////////////////////////////////////////////
  43. RegisterInformation::RegisterInformation()
  44. {
  45.   name=(char*)0;
  46.   hex_value=(char*)0;
  47.   description=(char*)0;
  48. }
  49.  
  50. ///////////////////////////////////////////////////////////////////////////////
  51. // The RegisterInformation destructor
  52. ///////////////////////////////////////////////////////////////////////////////
  53. RegisterInformation::~RegisterInformation()
  54. {
  55.   delete[] name;
  56.   delete[] hex_value;
  57.   delete[] description;
  58. }
  59.  
  60. ///////////////////////////////////////////////////////////////////////////////
  61. // Set the name, hex_value, and description of the register
  62. ///////////////////////////////////////////////////////////////////////////////
  63. void RegisterInformation::Set(const char* n,const char* v,const char *d)
  64. {
  65.   delete[] name;
  66.   delete[] hex_value;
  67.   delete[] description;
  68.  
  69.   name=new char[strlen(n)+1];
  70.   hex_value=new char[strlen(v)+1];
  71.   description=new char[strlen(d)+1];
  72.  
  73.   strcpy(name,n);
  74.   strcpy(hex_value,v);
  75.   strcpy(description,d);
  76. }
  77.  
  78.  
  79. ///////////////////////////////////////////////////////////////////////////////
  80. // The RegisterInformationList constructor
  81. ///////////////////////////////////////////////////////////////////////////////
  82. RegisterInformationList::RegisterInformationList(BasicCPU* cpu)
  83. {
  84.   head=tail=(void*)0;
  85.   number_of_elements=0;
  86.   cpu->BuildRegisterInformationList(this);
  87. }
  88.  
  89. ///////////////////////////////////////////////////////////////////////////////
  90. // The class destructor
  91. ///////////////////////////////////////////////////////////////////////////////
  92. RegisterInformationList::~RegisterInformationList()
  93. {
  94.   RegisterInformationNode* p;
  95.   RegisterInformationNode* q;
  96.  
  97.   // Delete the list of nodes
  98.   p=head;
  99.   while(p!=(void*)0)
  100.   {
  101.     q=p->next;
  102.     delete p;
  103.     p=q;
  104.   }
  105. }
  106.  
  107. ///////////////////////////////////////////////////////////////////////////////
  108. // Append a new node to the list
  109. ///////////////////////////////////////////////////////////////////////////////
  110. void RegisterInformationList::Append(const char* name,
  111.                                      const char* hex_value,
  112.                                      const char* description)
  113. {
  114.   RegisterInformationNode* n;
  115.   n = new RegisterInformationNode(name,hex_value,description);
  116.  
  117.   if(tail==(void*)0)
  118.   {
  119.     head = tail = n;
  120.   }
  121.   else
  122.   {
  123.     tail->next = n;
  124.     tail = n;
  125.   } 
  126.  
  127.   ++number_of_elements;
  128. }
  129.  
  130. ///////////////////////////////////////////////////////////////////////////////
  131. // Return a specific element from the list
  132. ///////////////////////////////////////////////////////////////////////////////
  133. int RegisterInformationList::Element(int index,RegisterInformation& info)
  134. {
  135.   RegisterInformationNode* p;
  136.   int t;
  137.  
  138.   for(t=0,p=head;(t<index) && (p!=(void*)0);++t,p=p->next);
  139.  
  140.   if (t==index) 
  141.   {
  142.     info.Set(p->Name(),p->HexValue(),p->Description());
  143.     return(1);
  144.   }
  145.   else
  146.   {
  147.     return(0);
  148.   }
  149. }
  150.  
  151.